package com.lyb.ui.lend.presenter;

import com.lyb.base.BasePresenter;
import com.lyb.http.HttpManager;
import com.lyb.http.HttpSubscriber;
import com.lyb.ui.lend.bean.ActivityBean;
import com.lyb.ui.lend.contract.ActivityContract;
import com.lyb.ui.my.bean.checkUploadBean;

/**
 * Created by xiejingwen on 2017/3/31 0031.
 */

public class ActivityPresenter extends BasePresenter<ActivityContract.View> implements ActivityContract.Presenter {

    public final String TYPE_LOAD_ACTIVITY = "loadActivity";
    public final String TYPE_CHECK_UPLOAD  = "checkUpload";

    @Override
    public void loadActivity() {
        toSubscribe(HttpManager.getApi().getActivityData(), new HttpSubscriber<ActivityBean>() {
            @Override
            protected void _onStart() {
                mView.showLoading("");
            }

            @Override
            protected void _onNext(ActivityBean activityBean) {
                if (activityBean != null) {
                    mView.loadActivitySuccess(activityBean);
                }
            }

            @Override
            protected void _onError(String message) {
                mView.showErrorMsg(message, TYPE_LOAD_ACTIVITY);
            }

            @Override
            protected void _onCompleted() {
                mView.stopLoading();
            }
        });
    }

    @Override
    public void checkUpload() {
        toSubscribe(HttpManager.getApi().checkUpload(), new HttpSubscriber<checkUploadBean>() {
            @Override
            protected void _onStart() {
                mView.showLoading("");
            }

            @Override
            protected void _onNext(checkUploadBean checkUploadBean) {
                mView.onCheckedSuccess(checkUploadBean.getStatus());
            }

            @Override
            protected void _onError(String message) {
                mView.showErrorMsg(message, TYPE_CHECK_UPLOAD);
            }

            @Override
            protected void _onCompleted() {
                mView.stopLoading();
            }
        });
    }
}
